﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Behaviors="clr-namespace:TwitterButtler.Behaviors"
    xmlns:ViewModels="clr-namespace:TwitterButtler.ViewModels"
    x:Class="TwitterButtler.Views.TwitterButtlerWindow"
    Title="Twitter Buttler"
    mc:Ignorable="d"
    SizeToContent="WidthAndHeight"
    MaxHeight="{x:Static SystemParameters.PrimaryScreenHeight}" MinHeight="200" MinWidth="200"
    WindowStyle="ToolWindow"
    d:DesignWidth="617.37" d:DesignHeight="363.98">

    <Window.Resources>
        <DataTemplate x:Key="LoginTemplate" DataType="{x:Type ViewModels:TwitterButtlerViewModel}">
            <Grid Background="Black" FocusManager.FocusedElement="{Binding ElementName=PinBox}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid TextBlock.FontSize="24" Grid.Column="1" Grid.Row="1" Margin="30">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Margin="3" FontSize="12" Foreground="LightBlue" MaxWidth="400" Text="Please log in to Twitter with the recipient account, and copy the PIN from the web page after accepting the access request" TextWrapping="Wrap" TextAlignment="Center" />

                    <Image Source="https://s3.amazonaws.com/twitter_production/a/1291835154/images/twitter_logo_s.png" Grid.Row="0" Grid.RowSpan="2" Stretch="Fill" StretchDirection="DownOnly" />

                    <Label Grid.Row="1" Grid.Column="1" Margin="3" Foreground="AliceBlue" Content="PIN:" />
                    <TextBox x:Name="PinBox" Grid.Row="1" Grid.Column="2" Margin="3" Text="{Binding TwitterPin, UpdateSourceTrigger=PropertyChanged}" AutoWordSelection="True" MinWidth="240" KeyDown="OnAccountBoxKeyDown" />

                    <Button Grid.Row="2" Grid.Column="2" Margin="3" Command="{Binding LogInCommand}" Content="Log In" Padding="12,6" VerticalContentAlignment="Center" HorizontalAlignment="Left"/>

                    <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Foreground="Red" Text="{Binding TwitterErrorMessage}" TextWrapping="Wrap" TextAlignment="Center" />
                </Grid>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="OnlineTemplate" DataType="{x:Type ViewModels:TwitterButtlerViewModel}">
            <Grid Background="{Binding TimelineProfileBackgroundColor}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <Image Source="{Binding TimelineProfileBackground}" Grid.Row="0" Grid.RowSpan="2" Stretch="Fill" StretchDirection="DownOnly" />

                <StackPanel Orientation="Horizontal" Grid.Row="0">
                    <Image Source="{Binding TimelineProfileImage}" Margin="3" Stretch="None" />

                    <TextBlock VerticalAlignment="Center"
                               Text="Direct Messages Received"
                               d:LayoutOverrides="Height"
                               Foreground="{Binding TimelineProfileTextColor}"
                               Margin="6"
                               FontSize="24"
                               TextAlignment="Left"
                               TextWrapping="Wrap"/>
                </StackPanel>

                <ListBox TextBlock.Foreground="{Binding TimelineProfileTextColor}"
                 ItemsSource="{Binding TimelineItems}"
                 Grid.Row="1"
                 Background="Transparent"
                 BorderThickness="0"
                 MinHeight="250" />
            </Grid>
        </DataTemplate>
    </Window.Resources>

    <Grid Behaviors:BusyIndicatorBehavior.BusyState="{Binding IsBusy}" Behaviors:BusyIndicatorBehavior.AddMargins="True">
        <ContentPresenter Content="{Binding}" Focusable="False">
            <ContentPresenter.Style>
                <Style TargetType="ContentPresenter">
                    <Setter Property="ContentTemplate" Value="{StaticResource LoginTemplate}" />

                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsOnline}" Value="True">
                            <Setter Property="ContentTemplate" Value="{StaticResource OnlineTemplate}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentPresenter.Style>
        </ContentPresenter>
    </Grid>
</Window>
